import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/guider_group";

export const header_api = (showError = true) => {
  return Http.get<{
    cate_arr: any[];
    in_china_arr: any[];
    out_china_arr: any[];
  }>(`/v3${baseUrl}/header`).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const index_api = (
  data: {
    cate_id?: number;
    province_id?: string;
    country_id?: string;
    keyword?: string;
  } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(`/v3${baseUrl}/index`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};
